//
//  VC2SegmentedControl.swift
//  ChapterAll
//
//  Created by Kevin on 2020/4/22.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VC2SegmentedControl: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let page = UISegmentedControl(items: ["one","two","three"])
        page.frame = CGRect(x: 10, y: 200, width: 200, height: 30)
        page.setImage(UIImage(named: "ic_action_anchor"), forSegmentAt: 1)
        //page.setContentOffset(CGSize(width: 10, height: 10), forSegmentAt: 2)
        //page.isMomentary = true
        page.selectedSegmentIndex = 0
        page.backgroundColor = UIColor.red
        view.addSubview(page)
        
        page.insertSegment(with: UIImage(named: "ic_action_anchor"), at: 2, animated: true)
        page.removeSegment(at: 2, animated: true)
        page.setTitle("33333333333333", forSegmentAt: 2)
        //page.setWidth(100, forSegmentAt: 2)
        page.apportionsSegmentWidthsByContent = true
        //page.removeAllSegments()
        
        page.addTarget(self, action: #selector(clickSegmentControl(ui:)), for: .valueChanged)
    }
    
    @objc func clickSegmentControl(ui:UISegmentedControl) -> Void {
        print("\(ui.selectedSegmentIndex)")
    }
}
